<?php 
class Zend_Service_Imageshack extends Zend_Service_Abstract 
{ 
       
    protected $_imageshacklogin = 'dev.imageshack.us'; 
 
    protected $_imgentrypoint = 'www.imageshack.us'; 
     
    protected $_videntrypoint = 'vid.imageshack.us'; 
     
    protected $_trnentrypoint = 'www.imageshack.us'; 
     
    /**
     * entrypoint choosen by _prepareParams
     * @var string
     */     
    protected $_backend; 
 
    /**
     * File types allowed by imageshack
     * @var array
     */     
    protected $_extensions = array( 
        'jpg', 'jpeg', 'png', 'gif', 'bmp', 'tif', 'tiff', 'flv' 
    ); 
 
    /**
     * Mime types required by Imageshack 'new' unified API
     * @var array
     */ 
    protected $_mimetypes = array( 
        'image/jpeg', 
        'image/jpeg', 
        'image/png', 
        'image/gif', 
        'image/bmp', 
        'image/tiff', 
        'image/tiff', 
        'video/x-flv' 
    ); 
 
    /**
     * Optimize image or not ?
     * @var bool
     */ 
    protected $_optimage; 
     
    /**
     * Imageshack login registration code
     * @var string
     */ 
    protected $_regCode; 
 
     
    /**
     * A comma-separated list of tags to add to your video/image. 
     * E.g. family,picture. Optional    
     * @var string
     */ 
    protected $_tags; 
     
    /**
     * Public/private marker of your video/picture. true means public (default), 
     * false means private.
     * @var bool
     */    
    protected $_public = true; 
     
    /**
     * tell to ImageShack to leave (false) or remove (true) information bar on 
     * thumbnail image generated by ImageShack. 
     * @var bool
     */    
    protected $_rembar = false; 
 
 
 
 
    /**
     * uploaded video dimensions in form WxH. Mandatory for video upload
     * @var string
     */    
    protected $_resolution; 
 
    /**
     * uploaded video duration in milliseconds. Mandatory for video upload. 
     * @var string
     */    
    protected $_duration; 
 
 
 
    /**
     * SimpleXML object after receiving response from imageshack
     * @var SimpleXML
     */    
    protected $_simplexml; 
 
 
    /**
     * raw xml response received from imageshack
     * @var string
     */        
    protected $_xmlresponse = null; 
     
     
    /**
     * Constructor
     * 
     * @param string $regCode Imageshack Registration Login Code
     * @return void
     */ 
    public function __construct($regCode = ""); 
 
    /**
     * Upload file to Imageshack with given mimetype
     * 
     * @param array $file
     * @return Zend_Service_Imageshack
     * @throws Zend_Service_Exception if something goes wrong
     */     
    public function uploadFileAs($filearr); 
 
 
    /**
     * Upload file to Imageshack
     * 
     * @param string $file
     * @param string $thumbfile optional video thumbnail picture
     * @param string $frmfile optional video default frame picture
     * @return Zend_Service_Imageshack
     * @throws Zend_Service_Exception if something goes wrong
     */         
    public function uploadFile($file, $thumbfile = null, $frmfile = null); 
   
     
    /**
     * Transload file to Imageshack
     * 
     * @param string $url
     * @return Zend_Service_Imageshack
     * @throws Zend_Service_Exception if something goes wrong
     */         
    public function transloadFile($url); 
 
    /**
     * Verify an Reg Login Code
     * 
     * @param string $key Optional; Reg Code key to verify
     * @return boolean
     */ 
    public function verifyRegCode($regcode = null); 
   
    protected function __get($param); 
     
    /**
     * Dumps raw XML responase as string
     * 
     * @return string
     */ 
    public function dumpXMLResponse(); 
 
    /**
     * Set Login Registration Code
     * 
     * @param string $regCode
     * @return Zend_Service_Imageshack
     */ 
    public function setRegCode($regCode); 
 
    /**
     * Retrieve API key
     * 
     * @return string
     */ 
    public function getRegCode(); 
     
    /**
     * A comma-separated list of tags to add to your video/image. 
     * E.g. family,picture. Optional
     * 
     * @param string $tags
     * @return Zend_Service_Imageshack
     */     
    public function addTags($tags); 
     
    /**
     * Public/private marker of your video/picture. true means public (default), 
     * false means private. Optional
     * 
     * @param bool $public
     * @return Zend_Service_Imageshack
     */     
    public function setPublic($public); 
     
    /**
     * Resize image on Imageshack's side
     * [axis1]x[axis2] ie. 640x480
     * @param string $res
     * @return Zend_Service_Imageshack
     */  
    public function resizeImage($res); 
     
    /**
     * Preserve (false) or remove (true) information bar on 
     * thumbnail image generated by ImageShack. 
     * @param bool $public
     * @return Zend_Service_Imageshack
     */  
    public function removeBar($remove); 
     
    /**
     * Sets the duration time for video
     * @param integer $duration
     * @return Zend_Service_Imageshack
     */  
    public function setDuration($duration); 
     
    /**
     * Sets the resolution of video
     * @param string $resolution
     * @return Zend_Service_Imageshack
     */  
    public function setResolution($resolution); 
 
    /**
     * checks is file readable
     *
     * @param string $file
     * @throws Zend_Service_Exception if file is not readable
     */  
    protected function _checkFile($file); 
 
    /**
     * return mimetype by file extension
     *
     * @param string $file
     * @return string
     */  
    protected function _getMimetypeByExtension($file); 
 
    /**
     * returns params array used to send request to imageshack and
     * sets $this->_backend to proper host
     *
     * @param string $mimetype
     * @return array
     */  
    protected function _prepareParams($mimetype); 
 
    /**
     * Checks resolution for proper syntax
     * @param string $resolution
     * @return Zend_Service_Imageshack
     */  
    protected function _checksize($res); 
 
    protected function _parseResponse($xmlresponse); 
     
    /**
     * Post a request
     * 
     * @param string $host 
     * @param string $path 
     * @param array  $params 
     * @return mixed
     */ 
    protected function _post($host, $path, array $params, $files = null); 
 
} 